package com.sylli.oeuf.server.game.logic.skill;

import java.util.ArrayList;
import java.util.Collection;

import com.sylli.oeuf.server.game.logic.ActionProduct;
import com.sylli.oeuf.server.game.logic.BattleActor;
import com.sylli.oeuf.server.game.logic.CastingTarget;
import com.sylli.oeuf.server.game.logic.EventParameter;
import com.sylli.oeuf.server.game.logic.Skill;
import com.sylli.oeuf.server.game.logic.action.CombatLog;
import com.sylli.oeuf.server.game.logic.action.Damage;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueElement;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueFlag;
import com.sylli.oeuf.server.game.logic.invocation.InvocationAction;
import com.sylli.oeuf.server.game.logic.invocation.InvocationCondition;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEntry;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEvent;

public class Vampire_SangueImbottire extends Skill {
	public Vampire_SangueImbottire() {
		super("sangue imbottire", CastingTarget.FocusTarget);
		this.getEntries().put(
				InvocationEvent.STD_IE_ON_ACTIVE,
				new InvocationEntry(
						InvocationCondition.ALWAYS_TRUE_IC,
						new InvocationAction() {
							@Override
							public Collection<ActionProduct> act(
									int rank, BattleActor caster,
									CastingTarget target,
									EventParameter ep) {
								
								// caster lose 10% of max HP
								// target take random damage corresponding to that amount
								// percentage of damage dealt can be calculated by (120% + ((rank - 1) * 30%))
								// Ex. 	rank1 = 120% of HP loss
								// 		rank2 = 150% of HP loss
								//		rank3 = 180% of HP loss
								int sacrifice = (int) (caster.getMaxHealth() * 0.1);
								double maxFactor = 1.2 + ((rank - 1) * 0.3);
								int damageFactor = (int) ((Math.random() * (maxFactor - 1.2)) + 1.2);
								int doDamage = (int) (sacrifice * damageFactor);
								
								Collection<ActionProduct> product = new ArrayList<ActionProduct>();
								Damage sacrificeProduct = new Damage(caster, 
										caster,
										sacrifice,
										ActionValueFlag.Normal,
										ActionValueElement.Shadow);
								product.add(sacrificeProduct);
								Damage damageProduct = new Damage(caster, 
										caster.getProperTarget(CastingTarget.FocusTarget),
										doDamage,
										ActionValueFlag.Normal,
										ActionValueElement.Shadow);
								product.add(damageProduct);
								product.add(new CombatLog(caster, caster.getProperTarget(CastingTarget.FocusTarget),
										caster.getName() + " suffered %p from [" + name + "].",
										sacrificeProduct));
								product.add(new CombatLog(caster, caster.getProperTarget(CastingTarget.FocusTarget),
										caster.getName() + " injected his deadly blood into " + caster.getProperTarget(CastingTarget.FocusTarget).getName() + " caused %p.",
										damageProduct));
								return product;
							}
						}));
	}

}